// $ANTLR 3.0.1 C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g 2008-03-18 20:59:50

package edu.calvin.djs32.cs214.interpreters.frontend;


import org.antlr.runtime.*;
import java.util.Stack;
import java.util.List;
import java.util.ArrayList;


import org.antlr.runtime.tree.*;

@SuppressWarnings("all")
public class Hobbes2008Parser extends Parser {
    public static final String[] tokenNames = new String[] {
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "TUPLE", "APPLICATION", "NUMBER", "HEXDIGIT", "SIGN", "INTEGER", "IDENTIFIER", "WHITESPACE", "COMMENTS", "STRING", "COMMA", "LPAREN", "RPAREN"
    };
    public static final int COMMA=14;
    public static final int INTEGER=9;
    public static final int HEXDIGIT=7;
    public static final int APPLICATION=5;
    public static final int EOF=-1;
    public static final int NUMBER=6;
    public static final int STRING=13;
    public static final int RPAREN=16;
    public static final int LPAREN=15;
    public static final int SIGN=8;
    public static final int TUPLE=4;
    public static final int COMMENTS=12;
    public static final int IDENTIFIER=10;
    public static final int WHITESPACE=11;

        public Hobbes2008Parser(TokenStream input) {
            super(input);
        }
        
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();

    public void setTreeAdaptor(TreeAdaptor adaptor) {
        this.adaptor = adaptor;
    }
    public TreeAdaptor getTreeAdaptor() {
        return adaptor;
    }

    public String[] getTokenNames() { return tokenNames; }
    public String getGrammarFileName() { return "C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g"; }

     
      protected void mismatch(IntStream input, int ttype, BitSet follow) 
        throws RecognitionException { 
        throw new MismatchedTokenException(ttype, input); 
      } 
      public void recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) 
        throws RecognitionException { 
        throw e; 
      } 


    public static class program_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start program
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:50:1: program : expression EOF ;
    public final program_return program() throws RecognitionException {
        program_return retval = new program_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token EOF2=null;
        expression_return expression1 = null;


        Object EOF2_tree=null;

        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:50:8: ( expression EOF )
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:50:10: expression EOF
            {
            root_0 = (Object)adaptor.nil();

            pushFollow(FOLLOW_expression_in_program78);
            expression1=expression();
            _fsp--;

            adaptor.addChild(root_0, expression1.getTree());
            EOF2=(Token)input.LT(1);
            match(input,EOF,FOLLOW_EOF_in_program80); 

            }

            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end program

    public static class expression_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start expression
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:77:1: expression : ( INTEGER | STRING | tuple | application );
    public final expression_return expression() throws RecognitionException {
        expression_return retval = new expression_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token INTEGER3=null;
        Token STRING4=null;
        tuple_return tuple5 = null;

        application_return application6 = null;


        Object INTEGER3_tree=null;
        Object STRING4_tree=null;

        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:77:12: ( INTEGER | STRING | tuple | application )
            int alt1=4;
            switch ( input.LA(1) ) {
            case INTEGER:
                {
                alt1=1;
                }
                break;
            case STRING:
                {
                alt1=2;
                }
                break;
            case LPAREN:
                {
                alt1=3;
                }
                break;
            case IDENTIFIER:
                {
                alt1=4;
                }
                break;
            default:
                NoViableAltException nvae =
                    new NoViableAltException("77:1: expression : ( INTEGER | STRING | tuple | application );", 1, 0, input);

                throw nvae;
            }

            switch (alt1) {
                case 1 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:77:20: INTEGER
                    {
                    root_0 = (Object)adaptor.nil();

                    INTEGER3=(Token)input.LT(1);
                    match(input,INTEGER,FOLLOW_INTEGER_in_expression432); 
                    INTEGER3_tree = (Object)adaptor.create(INTEGER3);
                    adaptor.addChild(root_0, INTEGER3_tree);


                    }
                    break;
                case 2 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:77:30: STRING
                    {
                    root_0 = (Object)adaptor.nil();

                    STRING4=(Token)input.LT(1);
                    match(input,STRING,FOLLOW_STRING_in_expression436); 
                    STRING4_tree = (Object)adaptor.create(STRING4);
                    adaptor.addChild(root_0, STRING4_tree);


                    }
                    break;
                case 3 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:77:39: tuple
                    {
                    root_0 = (Object)adaptor.nil();

                    pushFollow(FOLLOW_tuple_in_expression440);
                    tuple5=tuple();
                    _fsp--;

                    adaptor.addChild(root_0, tuple5.getTree());

                    }
                    break;
                case 4 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:77:47: application
                    {
                    root_0 = (Object)adaptor.nil();

                    pushFollow(FOLLOW_application_in_expression444);
                    application6=application();
                    _fsp--;

                    adaptor.addChild(root_0, application6.getTree());

                    }
                    break;

            }
            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end expression

    public static class application_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start application
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:78:1: application : identifier tuple -> ^( APPLICATION identifier tuple ) ;
    public final application_return application() throws RecognitionException {
        application_return retval = new application_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        identifier_return identifier7 = null;

        tuple_return tuple8 = null;


        RewriteRuleSubtreeStream stream_identifier=new RewriteRuleSubtreeStream(adaptor,"rule identifier");
        RewriteRuleSubtreeStream stream_tuple=new RewriteRuleSubtreeStream(adaptor,"rule tuple");
        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:78:12: ( identifier tuple -> ^( APPLICATION identifier tuple ) )
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:78:14: identifier tuple
            {
            pushFollow(FOLLOW_identifier_in_application450);
            identifier7=identifier();
            _fsp--;

            stream_identifier.add(identifier7.getTree());
            pushFollow(FOLLOW_tuple_in_application452);
            tuple8=tuple();
            _fsp--;

            stream_tuple.add(tuple8.getTree());

            // AST REWRITE
            // elements: tuple, identifier
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 78:31: -> ^( APPLICATION identifier tuple )
            {
                // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:78:34: ^( APPLICATION identifier tuple )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(adaptor.create(APPLICATION, "APPLICATION"), root_1);

                adaptor.addChild(root_1, stream_identifier.next());
                adaptor.addChild(root_1, stream_tuple.next());

                adaptor.addChild(root_0, root_1);
                }

            }



            }

            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end application

    public static class identifier_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start identifier
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:79:1: identifier : IDENTIFIER ;
    public final identifier_return identifier() throws RecognitionException {
        identifier_return retval = new identifier_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token IDENTIFIER9=null;

        Object IDENTIFIER9_tree=null;

        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:79:11: ( IDENTIFIER )
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:79:13: IDENTIFIER
            {
            root_0 = (Object)adaptor.nil();

            IDENTIFIER9=(Token)input.LT(1);
            match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_identifier468); 
            IDENTIFIER9_tree = (Object)adaptor.create(IDENTIFIER9);
            adaptor.addChild(root_0, IDENTIFIER9_tree);


            }

            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end identifier

    public static class tuple_return extends ParserRuleReturnScope {
        Object tree;
        public Object getTree() { return tree; }
    };

    // $ANTLR start tuple
    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:1: tuple : LPAREN ( expression ( COMMA expression )* )? RPAREN -> ^( TUPLE ( expression )* ) ;
    public final tuple_return tuple() throws RecognitionException {
        tuple_return retval = new tuple_return();
        retval.start = input.LT(1);

        Object root_0 = null;

        Token LPAREN10=null;
        Token COMMA12=null;
        Token RPAREN14=null;
        expression_return expression11 = null;

        expression_return expression13 = null;


        Object LPAREN10_tree=null;
        Object COMMA12_tree=null;
        Object RPAREN14_tree=null;
        RewriteRuleTokenStream stream_COMMA=new RewriteRuleTokenStream(adaptor,"token COMMA");
        RewriteRuleTokenStream stream_RPAREN=new RewriteRuleTokenStream(adaptor,"token RPAREN");
        RewriteRuleTokenStream stream_LPAREN=new RewriteRuleTokenStream(adaptor,"token LPAREN");
        RewriteRuleSubtreeStream stream_expression=new RewriteRuleSubtreeStream(adaptor,"rule expression");
        try {
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:6: ( LPAREN ( expression ( COMMA expression )* )? RPAREN -> ^( TUPLE ( expression )* ) )
            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:8: LPAREN ( expression ( COMMA expression )* )? RPAREN
            {
            LPAREN10=(Token)input.LT(1);
            match(input,LPAREN,FOLLOW_LPAREN_in_tuple474); 
            stream_LPAREN.add(LPAREN10);

            // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:15: ( expression ( COMMA expression )* )?
            int alt3=2;
            int LA3_0 = input.LA(1);

            if ( ((LA3_0>=INTEGER && LA3_0<=IDENTIFIER)||LA3_0==STRING||LA3_0==LPAREN) ) {
                alt3=1;
            }
            switch (alt3) {
                case 1 :
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:16: expression ( COMMA expression )*
                    {
                    pushFollow(FOLLOW_expression_in_tuple477);
                    expression11=expression();
                    _fsp--;

                    stream_expression.add(expression11.getTree());
                    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:27: ( COMMA expression )*
                    loop2:
                    do {
                        int alt2=2;
                        int LA2_0 = input.LA(1);

                        if ( (LA2_0==COMMA) ) {
                            alt2=1;
                        }


                        switch (alt2) {
                    	case 1 :
                    	    // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:28: COMMA expression
                    	    {
                    	    COMMA12=(Token)input.LT(1);
                    	    match(input,COMMA,FOLLOW_COMMA_in_tuple480); 
                    	    stream_COMMA.add(COMMA12);

                    	    pushFollow(FOLLOW_expression_in_tuple482);
                    	    expression13=expression();
                    	    _fsp--;

                    	    stream_expression.add(expression13.getTree());

                    	    }
                    	    break;

                    	default :
                    	    break loop2;
                        }
                    } while (true);


                    }
                    break;

            }

            RPAREN14=(Token)input.LT(1);
            match(input,RPAREN,FOLLOW_RPAREN_in_tuple488); 
            stream_RPAREN.add(RPAREN14);


            // AST REWRITE
            // elements: expression
            // token labels: 
            // rule labels: retval
            // token list labels: 
            // rule list labels: 
            retval.tree = root_0;
            RewriteRuleSubtreeStream stream_retval=new RewriteRuleSubtreeStream(adaptor,"token retval",retval!=null?retval.tree:null);

            root_0 = (Object)adaptor.nil();
            // 80:56: -> ^( TUPLE ( expression )* )
            {
                // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:59: ^( TUPLE ( expression )* )
                {
                Object root_1 = (Object)adaptor.nil();
                root_1 = (Object)adaptor.becomeRoot(adaptor.create(TUPLE, "TUPLE"), root_1);

                // C:\\Documents and Settings\\Derek\\workspace\\cs214\\CS 214 Interpreters\\src\\edu\\calvin\\djs32\\cs214\\interpreters\\frontend\\Hobbes2008.g:80:67: ( expression )*
                while ( stream_expression.hasNext() ) {
                    adaptor.addChild(root_1, stream_expression.next());

                }
                stream_expression.reset();

                adaptor.addChild(root_0, root_1);
                }

            }



            }

            retval.stop = input.LT(-1);

                retval.tree = (Object)adaptor.rulePostProcessing(root_0);
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);

        }
         
          catch (RecognitionException e) { 
            throw e; 
          } 
        finally {
        }
        return retval;
    }
    // $ANTLR end tuple


 

    public static final BitSet FOLLOW_expression_in_program78 = new BitSet(new long[]{0x0000000000000000L});
    public static final BitSet FOLLOW_EOF_in_program80 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_INTEGER_in_expression432 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_STRING_in_expression436 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_tuple_in_expression440 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_application_in_expression444 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_identifier_in_application450 = new BitSet(new long[]{0x0000000000008000L});
    public static final BitSet FOLLOW_tuple_in_application452 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_IDENTIFIER_in_identifier468 = new BitSet(new long[]{0x0000000000000002L});
    public static final BitSet FOLLOW_LPAREN_in_tuple474 = new BitSet(new long[]{0x000000000001A600L});
    public static final BitSet FOLLOW_expression_in_tuple477 = new BitSet(new long[]{0x0000000000014000L});
    public static final BitSet FOLLOW_COMMA_in_tuple480 = new BitSet(new long[]{0x000000000000A600L});
    public static final BitSet FOLLOW_expression_in_tuple482 = new BitSet(new long[]{0x0000000000014000L});
    public static final BitSet FOLLOW_RPAREN_in_tuple488 = new BitSet(new long[]{0x0000000000000002L});

}